/**
 * Created by IntelliJ IDEA.
 * @Author: xuybang
 * @version: 2017/5/25.
 * To change this template use File | Settings | File Templates.
 */
(function () {

    var x;

    function onInit() {

        onInitData();

    }

    // 初始化元素
    function onInitData() {
        onGetUserInfoShow();
    }

    /**
     * 获取用户信息
     */
    function onGetUserInfoShow() {
        var userId = backService.localLoginInfo.id;
        backService.user.onGetUserInfoShow(userId, function (json) {
//			console.log(json.data)
            var data = json.data;
            onShowUserInfo(data);
        }, function (e) {
            app.showToast(e.msg)
        });
    }

    /**
     * 显示用户信息
     * @param {Object} data
     */
    function onShowUserInfo(data) {
        var avatar = data.avatar;
        var nickname = data.nickName;
        var info = data.info;
        var friendNum = data.friendNum;
        var releaseNum = data.releaseNum;
        if (avatar) {
            var src = backService.getFileUrl(data.avatar);
            // x.$view.find('.avatar_img img').attr("src", src);
            x.$view.find('.avatar_img').css("background-image", "url(" + src + ")");
        } else {
            x.$view.find('.avatar_img').css("background-image", "url(img/message/index/head.jpg)");
            // x.$view.find('.avatar_img img').attr("src", "img/message/index/head.jpg");
        }
        x.$view.find('.user_name .text').text(nickname != null ? nickname : "您还没有设置昵称");
        x.$view.find('.mol_desc').text(info != null ? info : "您还没有编辑简介!");
        x.$view.find('.fri div').text(friendNum);
        x.$view.find('.word div').text(releaseNum);
    }

    /*初始化*/
    window.onViewInit_user_index = function (view) {
        x = view.context;
        onInit();
    };

    window.onViewShow_user_index = function (view) {
        x = view.context;

        app.onBackTabItemActive(x.$view, 4);
    };
})();